package LC;

/**
 * @ClassName LC.LC516
 * @Description: TODO
 * @Author hl
 * @Date 2020/5/21
 * @Version V1.0
 **/
public class LC516 {

    public static void main(String[] args) {

     String s="bbbab";
        System.out.println(longestPalindromeSubseq(s));
    }
    public static int longestPalindromeSubseq(String s) {
        if(s==null){
            return 0;
        }
        int n=s.length();
        int [][]dp=new int[n][n];

        for (int i=n-1;i>=0;i--){
            dp[i][i]=1;
            for(int j=i+1;j<n;j++){
                if(s.charAt(i)==s.charAt(j)){
                    dp[i][j]=dp[i+1][j-1]+2;

                }else{
                    dp[i][j]=Math.max(dp[i][j-1],dp[i+1][j]);
                }
            }

        }
        return dp[0][n-1];


    }



}
